<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="企业名称">
              <j-input placeholder="请输入企业名称" v-model="queryParam.enterpriseName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="企业信用代码">
              <j-input placeholder="请输入企业信用代码" v-model="queryParam.enterpriseCreditCode"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料大类">
              <a-select
                v-model="queryParam.provisionBroad"
                placeholder="请选择物料大类"
                :showSearch="true"
                :allowClear="true"
                :filterOption="filterOption"
                @change="handleChange"
                :getPopupContainer="(triggerNode)=>{ return triggerNode.parentNode}"
              >
                <a-select-option v-for="item in provisionBroadList" :key="item.id" :value="item.id">{{item.categoryName}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料小类">
              <a-select
                v-model="queryParam.provisionSmall"
                placeholder="请选择物料小类"
                :showSearch="true"
                :allowClear="true"
                :filterOption="filterOption"
                :getPopupContainer="triggerNode => {return triggerNode.parentNode}"
              >
                <a-select-option v-for="item in provisionSmallList" :key="item.id" :value="item.id">{{item.categoryName}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="主营业务">
              <j-input placeholder="请输入主营业务" v-model="queryParam.mainBussiness"></j-input>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="onClearSelected();searchQuery();" icon="search">查询</a-button>
              <a-button type="primary" @click="provisionSmallList=[],searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('供应商台账')" :disabled="isDisabledAuth('erpPurchaseSupplierStanding:export')">导出</a-button>
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x: '180%'}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
      </a-table>
    </div>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import {getAction} from '@/api/manage'

  export default {
    name: 'ErpPurchaseSupplierStandingList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
    },
    data () {
      return {
        description: '供应商台账管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'企业名称',
            align:"center",
            dataIndex: 'enterpriseName',
            width: 300,
            ellipsis: true,
          },
          {
            title:'企业信用代码',
            align:"center",
            width:300,
            dataIndex: 'enterpriseCreditCode',
            ellipsis: true,
          },
          {
            title:'企业类型',
            align:"center",
            width:200,
            dataIndex: 'enterpriseType_dictText',
            ellipsis: true,
          },
          {
            title:'法定代表人',
            align:"center",
            width:100,
            dataIndex: 'legalRepresentative',
            ellipsis: true,
          },
          {
            title:'企业地址',
            align:"center",
            width:300,
            dataIndex: 'enterpriseAddress',
            ellipsis: true,
          },
          {
            title:'授信等级',
            align:"center",
            width:100,
            dataIndex: 'creditRating_dictText',
            ellipsis: true,
            customRender:function (t,r,index) {
              return t || '--'
            }
          },
          {
            title:'合作次数',
            align:"center",
            width:100,
            dataIndex: 'cooperationNum',
            ellipsis: true,
          },
          {
            title:'企业注册时间',
            align:"center",
            width:200,
            dataIndex: 'registerDate',
            ellipsis: true,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'注册资本',
            align:"center",
            width:200,
            dataIndex: 'registerCapital',
            ellipsis: true,
          },
          {
            title:'开户行',
            align:"center",
            width:200,
            dataIndex: 'bankName',
            ellipsis: true,
          },
          {
            title:'银行账号',
            align:"center",
            width:200,
            dataIndex: 'bankAccountNo',
            ellipsis: true,
          },
          {
            title:'公司网址',
            align:"center",
            width:200,
            dataIndex: 'companyWeb',
            ellipsis: true,
          },
          {
            title:'物料大类',
            align:"center",
            width:200,
            dataIndex: 'provisionBroad_dictText',
            ellipsis: true,
          },
          {
            title:'物料小类',
            align:"center",
            width:200,
            dataIndex: 'provisionSmall_dictText',
            ellipsis: true,
          },
          {
            title:'主营业务',
            align:"center",
            width:200,
            dataIndex: 'mainBussiness',
            ellipsis: true,
          },
          {
            title:'联系信息',
            align:"center",
            width:200,
            dataIndex: 'contactInformation',
            ellipsis: true,
          },
        ],
        url: {
          list: "/api/erp/purchase/statistical/erpPurchaseSupplierStanding/list",
          exportXlsUrl: "/api/erp/purchase/statistical/erpPurchaseSupplierStanding/exportXls",
          queryProvisionBroadList: "/api/erp/purchase/material/erpMaterialCategory/queryAllParent",
          queryProvisionSmallList: "/api/erp/purchase/material/erpMaterialCategory/queryChildrenByParentId"
        },
        dictOptions:{},
        superFieldList:[],
        provisionBroadList: [],
        provisionSmallList: []
      }
    },
    created() {
      this.getSuperFieldList();
      this.findProvisionBroadList()
    },
    methods: {
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      findProvisionBroadList() {
        const that = this
        that.provisionBroadList = []
        getAction(this.url.queryProvisionBroadList).then(res => {
          if (res.success) {
            res.result.forEach((res) => {
              that.provisionBroadList.push({ 'id':res.id, 'categoryName':res.categoryName })
            })
          } else {
            that.$message.warning(res.message)
          }
        })
      },
      findProvisionSmallList(value) {
        const that = this
        const parentId = value
        getAction(this.url.queryProvisionSmallList, { parentId }).then(res => {
          if (res.success) {
            res.result.forEach((res) => {
              that.provisionSmallList.push({ 'id':res.id, 'categoryName':res.categoryName })
            })
          } else {
            that.$message.warning(res.message)
          }
        })
      },
      handleChange(value) {
        this.provisionSmallList = []
        this.$set(this.queryParam, 'provisionSmall', undefined);
        if (!!value) {
          this.findProvisionSmallList(value)
        }
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'enterpriseName',text:'企业名称',dictCode:''})
        fieldList.push({type:'string',value:'enterpriseCreditCode',text:'企业信用代码',dictCode:''})
        fieldList.push({type:'string',value:'enterpriseType',text:'企业类型',dictCode:''})
        fieldList.push({type:'string',value:'legalRepresentative',text:'法定代表人'})
        fieldList.push({type:'string',value:'enterpriseAddress',text:'企业地址',dictCode:''})
        fieldList.push({type:'date',value:'registerDate',text:'企业注册时间',dictCode:''})
        fieldList.push({type:'string',value:'registerCapital',text:'注册资本',dictCode:''})
        fieldList.push({type:'string',value:'bankName',text:'开户行',dictCode:''})
        fieldList.push({type:'string',value:'bankAccountNo',text:'银行账号',dictCode:''})
        fieldList.push({type:'string',value:'companyWeb',text:'公司网址',dictCode:''})
        fieldList.push({type:'string',value:'provisionBroad',text:'物料大类',dictCode:''})
        fieldList.push({type:'string',value:'provisionSmall',text:'物料小类',dictCode:''})
        fieldList.push({type:'string',value:'mainBussiness',text:'主营业务',dictCode:''})
        fieldList.push({type:'string',value:'contactInformation',text:'联系信息',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
